package gptma.fo.controler;

import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

/**
 * 
 * @author xcl
 */
public abstract class LazyResultPage<T> extends WebPage {

	private LazyDataModel<T> results;

	protected abstract List<T> fetchResults(int first, int pageSize);

	protected abstract Long getRowCount();

	@PostConstruct
	public void init() {
		results = new LazyDataModel<T>() {

			private static final long serialVersionUID = 3246375209430250909L;

			@Override
			@SuppressWarnings("unused")
			public List<T> load(int first, int pageSize, String sortField,
					SortOrder sortOrder, Map<String, String> filters) {
				return fetchResults(first, pageSize);
			}
		};
	}

	public LazyDataModel<T> getResults() {
		return results;
	}

}
